<!-- 任务配置_选择实体的弹窗 -->
<template>
    <el-dialog title="选择实体" width="340px" :visible.sync="dialogVisible" append-to-body :before-close="handleClose"
        :close-on-click-modal="false" :destroy-on-close="true">
        <div class="add-dialog">
            <Tree ref="addTreeRef" :treeData="treeData" :defaultExpandAll="true" :showCheckbox="false" :checkStrictlyUI="false">
            </Tree>
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button class="jtyj-btn-cancel" @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
        </span>

    </el-dialog>
</template>

<script>
import { getEntityTree } from "@/api/myspace/scenario-edit-tool/scenario-edit";
import Tree from "@/components/LeftTree/tree.vue";
export default {
    name: "AddDialog",
    data() {
        return {
            dialogVisible: false,
            treeData: [],
        }
    },
    components: {
        Tree,
    },
    props: {
        scenarioId: {
            type: Number,
            default: 0,
        },
    },
    created() {
        // 获取树节点数据
        this.getEntityTree({
            scenarioId: this.scenarioId,
        });
    },
    methods: {
        /**
         * 获取实体树
         * @param query 获取参数 {scenarioId: 1}
         */
        getEntityTree(query) {
            console.log(query);
            getEntityTree(query).then(response => {
                if (response.code === 200) {
                    this.treeData = response.data[0].commonTreeList;
                }
            })
        },

        handleClose(done) {
            this.dialogVisible = false;
        },
    },

}

</script>

<style lang="scss" scoped>
.add-dialog {
    width: 300px;
    height: 65vh;
}
</style>